//
//  BaseNavigationController.m
//  CloudWeibo
//
//  Created by CLOUD on 11/14/14.
//  Copyright (c) 2014 Cloud. All rights reserved.
//

#import "BaseNavigationController.h"
#import "ThemeManager.h"

@interface BaseNavigationController ()

@end

@implementation BaseNavigationController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeNotification) name:kThemeDidChangeNofication object:nil];
    }
    return self;
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}

- (void)themeNotification {
    [self loadThemeImage];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    /*
    float version = WXHLOSVersion();
    if (version >= 5.0) {
        UIImage *image = [UIImage imageNamed:@"navigationbar_background"];
        [self.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    }
     */
    [self loadThemeImage];
    
    
    UISwipeGestureRecognizer *swipGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipAction:)];
    swipGesture.direction = UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:swipGesture];
    [swipGesture release];
}

- (void)swipAction:(UIGestureRecognizer *) gesture
{
    if (self.viewControllers.count > 1) {
        [self popViewControllerAnimated:YES];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)loadThemeImage
{
    float version = WXHLOSVersion();
    if (version >= 5.0) {
        UIImage *image = [[ThemeManager shareInstance] getThemeImage:@"navigationbar_background.png"];
        //UIImage *image = [UIImage imageNamed:@"navigationbar_background"];
        [self.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    } else {
        [self.navigationBar setNeedsDisplay];
    }
}
@end
